<?php

class GenericID extends ID {
	private $classname;
	public function Serialize(){ return serialize(array('classname'=>$this->classname,'value'=>$this->value)); }
	public function Unserialize($data){ $a = unserialize($data); $this->classname=$a['classname']; $this->value=$a['value']; }

	public function __construct($classname,$value=null){
		parent::__construct($value);
		$this->classname = $classname;
	}
	public function IsEqual($id) {
		if ($id instanceof GenericID) return $this->classname == $id->classname && parent::IsEqual($id);
		if ($id instanceof DBItem) return $this->classname == $id->GetClassName() && parent::IsEqual($id);
		return parent::IsEqual($id);
	}
	public function ToDBItem(){
		return DBItem::RetrieveGeneric($this->classname,$this);
	}
	public function RetrieveDBItem(){
		return DBItem::RetrieveGeneric($this->classname,$this);
	}
	public function GetClassName(){
		return $this->GetClassName();
	}

	const DELIMETER = '~';
	public function Encode(){
		return $this->classname . self::DELIMETER .$this->AsHex();
	}
	public static function Decode($data){
		if (is_null($data)) return null;
		$a = explode(self::DELIMETER,$data);
		if (count($a) < 2) return null;
		return new GenericID($a[0],$a[1]);
	}

}


?>
